//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "BilinearInterpolation.h"
using namespace Cephei::QL::Math::Interpolations;
#include <gen/QL/Math/Matrix.h>
#include <gen/QL/Math/Interpolations/Interpolation2D.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Interpolations::CBilinearInterpolation::CBilinearInterpolation (boost::shared_ptr<QuantLib::BilinearInterpolation>& childNative, Object^ owner) : CInterpolation2D(CBilinearInterpolation::typeid)
{
#ifdef HANDLE
	_phBilinearInterpolation = NULL;
#endif
	_ppBilinearInterpolation = &childNative;
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppBilinearInterpolation));
}
Cephei::QL::Math::Interpolations::CBilinearInterpolation::CBilinearInterpolation (QuantLib::BilinearInterpolation& childNative, Object^ owner) : CInterpolation2D(CBilinearInterpolation::typeid)
{
#ifdef HANDLE
	_phBilinearInterpolation = NULL;
#endif
	_ppBilinearInterpolation = new boost::shared_ptr<QuantLib::BilinearInterpolation> (&childNative);
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppBilinearInterpolation));
    _BilinearInterpolationOwner = owner;
    _Interpolation2DOwner = owner;
}

Cephei::QL::Math::Interpolations::CBilinearInterpolation::CBilinearInterpolation (CBilinearInterpolation^ copy) : CInterpolation2D(CBilinearInterpolation::typeid)
{
#ifdef HANDLE
	_phBilinearInterpolation = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppBilinearInterpolation = new boost::shared_ptr<QuantLib::BilinearInterpolation> (copy->GetShared());
        _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppBilinearInterpolation));
    }
}
Cephei::QL::Math::Interpolations::CBilinearInterpolation::CBilinearInterpolation (System::Type^ t) : CInterpolation2D(CBilinearInterpolation::typeid)
{
#ifdef HANDLE
	_phBilinearInterpolation = NULL;
#endif
	if (!t->IsSubclassOf(CBilinearInterpolation::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Interpolations::CBilinearInterpolation::CBilinearInterpolation (QuantLib::Handle<QuantLib::BilinearInterpolation>& childNative, Object^ owner)  : CInterpolation2D(CBilinearInterpolation::typeid)
{
	_phBilinearInterpolation = &childNative;
	_ppBilinearInterpolation = &static_cast<boost::shared_ptr<QuantLib::BilinearInterpolation>>(childNative.currentLink());
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppBilinearInterpolation));
    _BilinearInterpolationOwner = owner;
}
Cephei::QL::Math::Interpolations::CBilinearInterpolation::CBilinearInterpolation (QuantLib::Handle<QuantLib::BilinearInterpolation> childNative)  : CInterpolation2D(CBilinearInterpolation::typeid)
{
	_phBilinearInterpolation = &childNative;
	_ppBilinearInterpolation = &static_cast<boost::shared_ptr<QuantLib::BilinearInterpolation>>(childNative.currentLink());
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppBilinearInterpolation));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Interpolations::CBilinearInterpolation::CBilinearInterpolation (QuantLib::BilinearInterpolation childNative)  : CInterpolation2D(CBilinearInterpolation::typeid)
{
#ifdef HANDLE
	_phBilinearInterpolation = NULL;
#endif
	_ppBilinearInterpolation = new boost::shared_ptr<QuantLib::BilinearInterpolation> (new QuantLib::BilinearInterpolation (childNative));
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppBilinearInterpolation));
}
#endif

Cephei::QL::Math::Interpolations::CBilinearInterpolation::~CBilinearInterpolation ()
{
    if (_ppBilinearInterpolation != NULL)
    {
	    delete _ppBilinearInterpolation;
        _ppBilinearInterpolation = NULL;
    }
}
Cephei::QL::Math::Interpolations::CBilinearInterpolation::!CBilinearInterpolation ()
{
    if (_ppBilinearInterpolation != NULL)
    {
	    delete _ppBilinearInterpolation;
    }
}
QuantLib::BilinearInterpolation& Cephei::QL::Math::Interpolations::CBilinearInterpolation::GetReference ()
{
    if (_ppBilinearInterpolation == NULL) throw gcnew NativeNullException ();
	return **_ppBilinearInterpolation;
}
boost::shared_ptr<QuantLib::BilinearInterpolation>& Cephei::QL::Math::Interpolations::CBilinearInterpolation::GetShared ()
{
    if (_ppBilinearInterpolation == NULL) throw gcnew NativeNullException ();
	return *_ppBilinearInterpolation;
}
QuantLib::BilinearInterpolation* Cephei::QL::Math::Interpolations::CBilinearInterpolation::GetPointer ()
{
    if (_ppBilinearInterpolation == NULL) throw gcnew NativeNullException ();
	return &**_ppBilinearInterpolation;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::BilinearInterpolation>& Cephei::QL::Math::Interpolations::CBilinearInterpolation::GetHandle ()
{
	if (_phBilinearInterpolation == NULL)
	{
		_phBilinearInterpolation = new Handle<QuantLib::BilinearInterpolation> (*_ppBilinearInterpolation);
	}
	return *_phBilinearInterpolation;
}
#endif
bool Cephei::QL::Math::Interpolations::CBilinearInterpolation::HasNative () 
{
	return (_ppBilinearInterpolation != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

